<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="echarts5图表渲染过程分析, Java，Flutter，Dart，架构，编程，技术分享，读书分享">
    <meta name="description" content="Echarts快速入门Echarts就不做过多介绍了，相信大家都听说或者使用过，现在以官方给的第一个快速入门为基础，分析一下渲染过程。示例代码如下
&amp;lt;div id=&#34;main&#34; style=&#34;width: 600px;height:4">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>echarts5图表渲染过程分析 | 武码公社</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 5.4.0"></head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">武码公社</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a target="_blank" rel="noopener" href="https://lox.dengwu.wang" class="waves-effect waves-light">
      
      <i class="fas fa-book" style="zoom: 0.6;"></i>
      
      <span>自己动手写解释器</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">武码公社</div>
        <div class="logo-desc">
            
            思考和积累
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a target="_blank" rel="noopener" href="https://lox.dengwu.wang" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-book"></i>
			
			自己动手写解释器
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/wangdengwu" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>我的代码库
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/wangdengwu" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="我的代码库" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/12.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">echarts5图表渲染过程分析</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/%E5%9B%BE%E8%A1%A8-echarts/">
                                <span class="chip bg-color">图表 - echarts</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E5%89%8D%E7%AB%AF/" class="post-category">
                                前端
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-11-10
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-07-18
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    3.3k
                </div>
                

                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h3 id="Echarts快速入门"><a href="#Echarts快速入门" class="headerlink" title="Echarts快速入门"></a>Echarts快速入门</h3><p>Echarts就不做过多介绍了，相信大家都听说或者使用过，现在以官方给的第一个快速入门为基础，分析一下渲染过程。示例代码如下</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token operator">&lt;</span>div id<span class="token operator">=</span><span class="token string">"main"</span> style<span class="token operator">=</span><span class="token string">"width: 600px;height:400px;"</span><span class="token operator">></span><span class="token operator">&lt;</span><span class="token operator">/</span>div<span class="token operator">></span>
<span class="token operator">&lt;</span>script type<span class="token operator">=</span><span class="token string">"text/javascript"</span><span class="token operator">></span>

    <span class="token comment">// 基于准备好的dom，初始化echarts实例</span>
    <span class="token keyword">var</span> myChart <span class="token operator">=</span> echarts<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">'main'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 指定图表的配置项和数据</span>
    <span class="token keyword">var</span> option <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
      title<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
        text<span class="token operator">:</span> <span class="token string">'ECharts 入门示例'</span>
      <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
      tooltip<span class="token operator">:</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
      legend<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
        data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'销量'</span><span class="token punctuation">]</span>
      <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
      xAxis<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
        data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'衬衫'</span><span class="token punctuation">,</span> <span class="token string">'羊毛衫'</span><span class="token punctuation">,</span> <span class="token string">'雪纺衫'</span><span class="token punctuation">,</span> <span class="token string">'裤子'</span><span class="token punctuation">,</span> <span class="token string">'高跟鞋'</span><span class="token punctuation">,</span> <span class="token string">'袜子'</span><span class="token punctuation">]</span>
      <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
      yAxis<span class="token operator">:</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
      series<span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">&#123;</span>
          name<span class="token operator">:</span> <span class="token string">'销量'</span><span class="token punctuation">,</span>
          type<span class="token operator">:</span> <span class="token string">'bar'</span><span class="token punctuation">,</span>
          data<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">36</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">]</span>
        <span class="token punctuation">&#125;</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">&#125;</span><span class="token punctuation">;</span>

    <span class="token comment">// 使用刚指定的配置项和数据显示图表。</span>
    myChart<span class="token punctuation">.</span><span class="token function">setOption</span><span class="token punctuation">(</span>option<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>渲染出来的效果就是这样的<br><img src="https://img.dengwu.wang/blog/20211112181806.png"></p>
<h3 id="代码分析"><a href="#代码分析" class="headerlink" title="代码分析"></a>代码分析</h3><p>echarts是依赖zrender来绘制的，上述代码可以看到调用了echarts的2个方法，<strong>init</strong>和<strong>setOption</strong>,5.x版本的echarts是使用typescript写的。<br>先看下init方法的定义,在src/echarts.ts里,为了更简洁清晰，后续代码我删掉了非主干流程渲染的部分内容。</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">import</span> <span class="token punctuation">&#123;</span> init <span class="token punctuation">&#125;</span> <span class="token keyword">from</span> <span class="token string">'./core/echarts'</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">&#123;</span>
    <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">return</span> <span class="token function">init</span><span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> arguments<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>真正的init方法其实是./core/echarts里的</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">init</span><span class="token punctuation">(</span>
    <span class="token parameter">dom<span class="token operator">:</span> HTMLElement<span class="token punctuation">,</span>
    theme<span class="token operator">?</span><span class="token operator">:</span> string <span class="token operator">|</span> object<span class="token punctuation">,</span>
    opts<span class="token operator">?</span><span class="token operator">:</span> EChartsInitOpts</span>
<span class="token punctuation">)</span><span class="token operator">:</span> EChartsType <span class="token punctuation">&#123;</span>
    <span class="token keyword">const</span> existInstance <span class="token operator">=</span> <span class="token function">getInstanceByDom</span><span class="token punctuation">(</span>dom<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>existInstance<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
         <span class="token keyword">return</span> existInstance<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
    <span class="token keyword">const</span> chart <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ECharts</span><span class="token punctuation">(</span>dom<span class="token punctuation">,</span> theme<span class="token punctuation">,</span> opts<span class="token punctuation">)</span><span class="token punctuation">;</span>
    chart<span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token string">'ec_'</span> <span class="token operator">+</span> idBase<span class="token operator">++</span><span class="token punctuation">;</span>
    instances<span class="token punctuation">[</span>chart<span class="token punctuation">.</span>id<span class="token punctuation">]</span> <span class="token operator">=</span> chart<span class="token punctuation">;</span>

    modelUtil<span class="token punctuation">.</span><span class="token function">setAttribute</span><span class="token punctuation">(</span>dom<span class="token punctuation">,</span> <span class="token constant">DOM_ATTRIBUTE_KEY</span><span class="token punctuation">,</span> chart<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">enableConnect</span><span class="token punctuation">(</span>chart<span class="token punctuation">)</span><span class="token punctuation">;</span>

    lifecycle<span class="token punctuation">.</span><span class="token function">trigger</span><span class="token punctuation">(</span><span class="token string">'afterinit'</span><span class="token punctuation">,</span> chart<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">return</span> chart<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>代码实例化了ECharts对象，构造函数代码</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">class</span> <span class="token class-name">ECharts</span> <span class="token keyword">extends</span> <span class="token class-name">Eventful</span><span class="token operator">&lt;</span>ECEventDefinition<span class="token operator">></span> <span class="token punctuation">&#123;</span>
	 <span class="token function">constructor</span><span class="token punctuation">(</span>
	        dom<span class="token operator">:</span> HTMLElement<span class="token punctuation">,</span>
	        <span class="token comment">// Theme name or themeOption.</span>
	        theme<span class="token operator">?</span><span class="token operator">:</span> string <span class="token operator">|</span> ThemeOption<span class="token punctuation">,</span>
	        opts<span class="token operator">?</span><span class="token operator">:</span> EChartsInitOpts
	    <span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	        <span class="token keyword">super</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">ECEventProcessor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        opts <span class="token operator">=</span> opts <span class="token operator">||</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// Get theme by name</span>
	        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> theme <span class="token operator">===</span> <span class="token string">'string'</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
	            theme <span class="token operator">=</span> themeStorage<span class="token punctuation">[</span>theme<span class="token punctuation">]</span> <span class="token keyword">as</span> object<span class="token punctuation">;</span>
	        <span class="token punctuation">&#125;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_dom <span class="token operator">=</span> dom<span class="token punctuation">;</span>
	
	        <span class="token keyword">let</span> defaultRenderer <span class="token operator">=</span> <span class="token string">'canvas'</span><span class="token punctuation">;</span>
	        <span class="token keyword">let</span> defaultUseDirtyRect <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
	        
	        <span class="token keyword">const</span> zr <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_zr <span class="token operator">=</span> zrender<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>dom<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
	            renderer<span class="token operator">:</span> opts<span class="token punctuation">.</span>renderer <span class="token operator">||</span> defaultRenderer<span class="token punctuation">,</span>
	            devicePixelRatio<span class="token operator">:</span> opts<span class="token punctuation">.</span>devicePixelRatio<span class="token punctuation">,</span>
	            width<span class="token operator">:</span> opts<span class="token punctuation">.</span>width<span class="token punctuation">,</span>
	            height<span class="token operator">:</span> opts<span class="token punctuation">.</span>height<span class="token punctuation">,</span>
	            useDirtyRect<span class="token operator">:</span> opts<span class="token punctuation">.</span>useDirtyRect <span class="token operator">==</span> <span class="token keyword">null</span> <span class="token operator">?</span> defaultUseDirtyRect <span class="token operator">:</span> opts<span class="token punctuation">.</span>useDirtyRect
	        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// Expect 60 fps.</span>
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_throttledZrFlush <span class="token operator">=</span> <span class="token function">throttle</span><span class="token punctuation">(</span><span class="token function">bind</span><span class="token punctuation">(</span>zr<span class="token punctuation">.</span>flush<span class="token punctuation">,</span> zr<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">17</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        theme <span class="token operator">=</span> <span class="token function">clone</span><span class="token punctuation">(</span>theme<span class="token punctuation">)</span><span class="token punctuation">;</span>
	        theme <span class="token operator">&amp;&amp;</span> <span class="token function">backwardCompat</span><span class="token punctuation">(</span>theme <span class="token keyword">as</span> ECUnitOption<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_theme <span class="token operator">=</span> theme<span class="token punctuation">;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_locale <span class="token operator">=</span> <span class="token function">createLocaleObject</span><span class="token punctuation">(</span>opts<span class="token punctuation">.</span>locale <span class="token operator">||</span> <span class="token constant">SYSTEM_LANG</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_coordSysMgr <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CoordinateSystemManager</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token keyword">const</span> api <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_api <span class="token operator">=</span> <span class="token function">createExtensionAPI</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// Sort on demand</span>
	        <span class="token keyword">function</span> <span class="token function">prioritySortFunc</span><span class="token punctuation">(</span><span class="token parameter">a<span class="token operator">:</span> StageHandlerInternal<span class="token punctuation">,</span> b<span class="token operator">:</span> StageHandlerInternal</span><span class="token punctuation">)</span><span class="token operator">:</span> number <span class="token punctuation">&#123;</span>
	            <span class="token keyword">return</span> a<span class="token punctuation">.</span>__prio <span class="token operator">-</span> b<span class="token punctuation">.</span>__prio<span class="token punctuation">;</span>
	        <span class="token punctuation">&#125;</span>
	        <span class="token function">timsort</span><span class="token punctuation">(</span>visualFuncs<span class="token punctuation">,</span> prioritySortFunc<span class="token punctuation">)</span><span class="token punctuation">;</span>
	        <span class="token function">timsort</span><span class="token punctuation">(</span>dataProcessorFuncs<span class="token punctuation">,</span> prioritySortFunc<span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_scheduler <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scheduler</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> api<span class="token punctuation">,</span> dataProcessorFuncs<span class="token punctuation">,</span> visualFuncs<span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token keyword">this</span><span class="token punctuation">.</span>_messageCenter <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">MessageCenter</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// Init mouse events</span>
	        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_initEvents</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// In case some people write `window.onresize = chart.resize`</span>
	        <span class="token keyword">this</span><span class="token punctuation">.</span>resize <span class="token operator">=</span> <span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>resize<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        zr<span class="token punctuation">.</span>animation<span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">'frame'</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_onframe<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token function">bindRenderedEvent</span><span class="token punctuation">(</span>zr<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token function">bindMouseEvent</span><span class="token punctuation">(</span>zr<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	        <span class="token comment">// ECharts instance can be used as value.</span>
	        <span class="token function">setAsPrimitive</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	  <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>内容比较多，重点代码是初始化了zrender</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">const</span> zr <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_zr <span class="token operator">=</span> zrender<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>dom<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
	            renderer<span class="token operator">:</span> opts<span class="token punctuation">.</span>renderer <span class="token operator">||</span> defaultRenderer<span class="token punctuation">,</span>
	            devicePixelRatio<span class="token operator">:</span> opts<span class="token punctuation">.</span>devicePixelRatio<span class="token punctuation">,</span>
	            width<span class="token operator">:</span> opts<span class="token punctuation">.</span>width<span class="token punctuation">,</span>
	            height<span class="token operator">:</span> opts<span class="token punctuation">.</span>height<span class="token punctuation">,</span>
	            useDirtyRect<span class="token operator">:</span> opts<span class="token punctuation">.</span>useDirtyRect <span class="token operator">==</span> <span class="token keyword">null</span> <span class="token operator">?</span> defaultUseDirtyRect <span class="token operator">:</span> opts<span class="token punctuation">.</span>useDirtyRect
 <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>初始化了<code>this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);</code>,后续series渲染的时候会用到。<br>同时注册了渲染回调<code>zr.animation.on(&#39;frame&#39;, this._onframe, this);</code></p>
<p>在分析setOption方法之前，有必要先说一下echarts的组件设计思想，我们示例里看到的绘制出来的图形，其实是很多组件构成的，echarts主要分成2类，一类是ComponentView，一类是ChartView。分别在src/chart下面和src/component下面。<br>先看下父类ComponentView(src/view/Component.ts)定义</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">class</span> <span class="token class-name">ComponentView</span> <span class="token punctuation">&#123;</span>
    readonly group<span class="token operator">:</span> ViewRootGroup<span class="token punctuation">;</span>
    readonly uid<span class="token operator">:</span> string<span class="token punctuation">;</span>
    __model<span class="token operator">:</span> ComponentModel<span class="token punctuation">;</span>
    __alive<span class="token operator">:</span> boolean<span class="token punctuation">;</span>
    __id<span class="token operator">:</span> string<span class="token punctuation">;</span>

    <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>group <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Group</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>uid <span class="token operator">=</span> componentUtil<span class="token punctuation">.</span><span class="token function">getUID</span><span class="token punctuation">(</span><span class="token string">'viewComponent'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">init</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>

    <span class="token function">render</span><span class="token punctuation">(</span>model<span class="token operator">:</span> ComponentModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>

    <span class="token function">dispose</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>

    <span class="token function">updateView</span><span class="token punctuation">(</span>model<span class="token operator">:</span> ComponentModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">// Do nothing;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">updateLayout</span><span class="token punctuation">(</span>model<span class="token operator">:</span> ComponentModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">// Do nothing;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">updateVisual</span><span class="token punctuation">(</span>model<span class="token operator">:</span> ComponentModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">// Do nothing;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">/**
     * Hook for blur target series.
     * Can be used in marker for blur the markers
     */</span>
    <span class="token function">blurSeries</span><span class="token punctuation">(</span>seriesModels<span class="token operator">:</span> SeriesModel<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
         <span class="token comment">// Do nothing;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token keyword">static</span> registerClass<span class="token operator">:</span> clazzUtil<span class="token punctuation">.</span>ClassManager<span class="token punctuation">[</span><span class="token string">'registerClass'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>最主要的2个方法init和render是由各个组件子类来实现的。<br>ChartView(src/view/Chart.ts)</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">class</span> <span class="token class-name">ChartView</span> <span class="token punctuation">&#123;</span>
    type<span class="token operator">:</span> string<span class="token punctuation">;</span>
    readonly group<span class="token operator">:</span> ViewRootGroup<span class="token punctuation">;</span>
    readonly uid<span class="token operator">:</span> string<span class="token punctuation">;</span>
    readonly renderTask<span class="token operator">:</span> SeriesTask<span class="token punctuation">;</span>
    ignoreLabelLineUpdate<span class="token operator">:</span> boolean<span class="token punctuation">;</span>
    __alive<span class="token operator">:</span> boolean<span class="token punctuation">;</span>
    __model<span class="token operator">:</span> SeriesModel<span class="token punctuation">;</span>
    __id<span class="token operator">:</span> string<span class="token punctuation">;</span>

    <span class="token keyword">static</span> protoInitialize <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> proto <span class="token operator">=</span> <span class="token class-name">ChartView</span><span class="token punctuation">.</span>prototype<span class="token punctuation">;</span>
        proto<span class="token punctuation">.</span>type <span class="token operator">=</span> <span class="token string">'chart'</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>group <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Group</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>uid <span class="token operator">=</span> componentUtil<span class="token punctuation">.</span><span class="token function">getUID</span><span class="token punctuation">(</span><span class="token string">'viewChart'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span>renderTask <span class="token operator">=</span> createTask<span class="token operator">&lt;</span>SeriesTaskContext<span class="token operator">></span><span class="token punctuation">(</span><span class="token punctuation">&#123;</span>
            plan<span class="token operator">:</span> renderTaskPlan<span class="token punctuation">,</span>
            reset<span class="token operator">:</span> renderTaskReset
        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>renderTask<span class="token punctuation">.</span>context <span class="token operator">=</span> <span class="token punctuation">&#123;</span>view<span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">&#125;</span> <span class="token keyword">as</span> SeriesTaskContext<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">init</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>

    <span class="token function">render</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>

    <span class="token function">highlight</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token function">toggleHighlight</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">.</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> payload<span class="token punctuation">,</span> <span class="token string">'emphasis'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">downplay</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token function">toggleHighlight</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">.</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> payload<span class="token punctuation">,</span> <span class="token string">'normal'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token function">remove</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>group<span class="token punctuation">.</span><span class="token function">removeAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
    <span class="token function">dispose</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span>
    <span class="token function">updateView</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">// FIXME never used?</span>
    <span class="token function">updateLayout</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token comment">// FIXME never used?</span>
    <span class="token function">updateVisual</span><span class="token punctuation">(</span>seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token keyword">static</span> <span class="token function">markUpdateMethod</span><span class="token punctuation">(</span>payload<span class="token operator">:</span> Payload<span class="token punctuation">,</span> methodName<span class="token operator">:</span> keyof ChartView<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token function">inner</span><span class="token punctuation">(</span>payload<span class="token punctuation">)</span><span class="token punctuation">.</span>updateMethod <span class="token operator">=</span> methodName<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>

    <span class="token keyword">static</span> registerClass<span class="token operator">:</span> clazzUtil<span class="token punctuation">.</span>ClassManager<span class="token punctuation">[</span><span class="token string">'registerClass'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>也是需要关注init和render方法，但是额外不一样的是构造函数里初始化了renderTask，这块在渲染数据的时候会用到。<br>下面再回到setOption方法，我们来看看setOption(src/core/echarts.ts)的实现</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript">setOption<span class="token operator">&lt;</span>Opt <span class="token keyword">extends</span> <span class="token class-name">ECBasicOption</span><span class="token operator">></span><span class="token punctuation">(</span>option<span class="token operator">:</span> Opt<span class="token punctuation">,</span> notMerge<span class="token operator">?</span><span class="token operator">:</span> boolean <span class="token operator">|</span> SetOptionOpts<span class="token punctuation">,</span> lazyUpdate<span class="token operator">?</span><span class="token operator">:</span> boolean<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>_disposed<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token function">disposedWarning</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token keyword">let</span> silent<span class="token punctuation">;</span>
        <span class="token keyword">let</span> replaceMerge<span class="token punctuation">;</span>
        <span class="token keyword">let</span> transitionOpt<span class="token operator">:</span> SetOptionTransitionOpt<span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">isObject</span><span class="token punctuation">(</span>notMerge<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            lazyUpdate <span class="token operator">=</span> notMerge<span class="token punctuation">.</span>lazyUpdate<span class="token punctuation">;</span>
            silent <span class="token operator">=</span> notMerge<span class="token punctuation">.</span>silent<span class="token punctuation">;</span>
            replaceMerge <span class="token operator">=</span> notMerge<span class="token punctuation">.</span>replaceMerge<span class="token punctuation">;</span>
            transitionOpt <span class="token operator">=</span> notMerge<span class="token punctuation">.</span>transition<span class="token punctuation">;</span>
            notMerge <span class="token operator">=</span> notMerge<span class="token punctuation">.</span>notMerge<span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">IN_MAIN_PROCESS_KEY</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span>_model <span class="token operator">||</span> notMerge<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">const</span> optionManager <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">OptionManager</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>_api<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">const</span> theme <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_theme<span class="token punctuation">;</span>
            <span class="token keyword">const</span> ecModel <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_model <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">GlobalModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            ecModel<span class="token punctuation">.</span>scheduler <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_scheduler<span class="token punctuation">;</span>
            ecModel<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> theme<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_locale<span class="token punctuation">,</span> optionManager<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span>_model<span class="token punctuation">.</span><span class="token function">setOption</span><span class="token punctuation">(</span>option <span class="token keyword">as</span> ECBasicOption<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span> replaceMerge <span class="token punctuation">&#125;</span><span class="token punctuation">,</span> optionPreprocessorFuncs<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">const</span> updateParams <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
            seriesTransition<span class="token operator">:</span> transitionOpt<span class="token punctuation">,</span>
            optionChanged<span class="token operator">:</span> <span class="token boolean">true</span>
        <span class="token punctuation">&#125;</span> <span class="token keyword">as</span> UpdateLifecycleParams<span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>lazyUpdate<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
                silent<span class="token operator">:</span> silent<span class="token punctuation">,</span>
                updateParams<span class="token operator">:</span> updateParams
            <span class="token punctuation">&#125;</span><span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">IN_MAIN_PROCESS_KEY</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>

            <span class="token comment">// `setOption(option, &#123;lazyMode: true&#125;)` may be called when zrender has been slept.</span>
            <span class="token comment">// It should wake it up to make sure zrender start to render at the next frame.</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getZr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">wakeUp</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
            <span class="token function">prepare</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            updateMethods<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> updateParams<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token comment">// Ensure zr refresh sychronously, and then pixel in canvas can be</span>
            <span class="token comment">// fetched after `setOption`.</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>_zr<span class="token punctuation">.</span><span class="token function">flush</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">IN_MAIN_PROCESS_KEY</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>

            <span class="token function">flushPendingActions</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> silent<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token function">triggerUpdatedEvent</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> silent<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>初始化model，<code>this._model.setOption(option as ECBasicOption, &#123; replaceMerge &#125;, optionPreprocessorFuncs);</code><br><code>prepare(this);</code>的方法实现</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function-variable function">prepare</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">ecIns<span class="token operator">:</span> ECharts</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">const</span> scheduler <span class="token operator">=</span> ecIns<span class="token punctuation">.</span>_scheduler<span class="token punctuation">;</span>

            scheduler<span class="token punctuation">.</span><span class="token function">restorePipelines</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">.</span>_model<span class="token punctuation">)</span><span class="token punctuation">;</span>
            scheduler<span class="token punctuation">.</span><span class="token function">prepareStageTasks</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token function">prepareView</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token function">prepareView</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            scheduler<span class="token punctuation">.</span><span class="token function">plan</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function">restorePipelines</span><span class="token punctuation">(</span>ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> scheduler <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> pipelineMap <span class="token operator">=</span> scheduler<span class="token punctuation">.</span>_pipelineMap <span class="token operator">=</span> <span class="token function">createHashMap</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        ecModel<span class="token punctuation">.</span><span class="token function">eachSeries</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">seriesModel</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">const</span> progressive <span class="token operator">=</span> seriesModel<span class="token punctuation">.</span><span class="token function">getProgressive</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">const</span> pipelineId <span class="token operator">=</span> seriesModel<span class="token punctuation">.</span>uid<span class="token punctuation">;</span>

            pipelineMap<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span>pipelineId<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
                id<span class="token operator">:</span> pipelineId<span class="token punctuation">,</span>
                head<span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">,</span>
                tail<span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">,</span>
                threshold<span class="token operator">:</span> seriesModel<span class="token punctuation">.</span><span class="token function">getProgressiveThreshold</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                progressiveEnabled<span class="token operator">:</span> progressive
                    <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">.</span>preventIncremental <span class="token operator">&amp;&amp;</span> seriesModel<span class="token punctuation">.</span><span class="token function">preventIncremental</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                blockIndex<span class="token operator">:</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span>
                step<span class="token operator">:</span> Math<span class="token punctuation">.</span><span class="token function">round</span><span class="token punctuation">(</span>progressive <span class="token operator">||</span> <span class="token number">700</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                count<span class="token operator">:</span> <span class="token number">0</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            scheduler<span class="token punctuation">.</span><span class="token function">_pipe</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> seriesModel<span class="token punctuation">.</span>dataTask<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>其中seriesModel的内容:<br><img src="https://img.dengwu.wang/blog/20211113135714.png"></p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">private</span> <span class="token function">_pipe</span><span class="token punctuation">(</span><span class="token parameter">seriesModel<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> task<span class="token operator">:</span> GeneralTask</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> pipelineId <span class="token operator">=</span> seriesModel<span class="token punctuation">.</span>uid<span class="token punctuation">;</span>
        <span class="token keyword">const</span> pipeline <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_pipelineMap<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span>pipelineId<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">!</span>pipeline<span class="token punctuation">.</span>head <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>pipeline<span class="token punctuation">.</span>head <span class="token operator">=</span> task<span class="token punctuation">)</span><span class="token punctuation">;</span>
        pipeline<span class="token punctuation">.</span>tail <span class="token operator">&amp;&amp;</span> pipeline<span class="token punctuation">.</span>tail<span class="token punctuation">.</span><span class="token function">pipe</span><span class="token punctuation">(</span>task<span class="token punctuation">)</span><span class="token punctuation">;</span>
        pipeline<span class="token punctuation">.</span>tail <span class="token operator">=</span> task<span class="token punctuation">;</span>
        task<span class="token punctuation">.</span>__idxInPipeline <span class="token operator">=</span> pipeline<span class="token punctuation">.</span>count<span class="token operator">++</span><span class="token punctuation">;</span>
        task<span class="token punctuation">.</span>__pipeline <span class="token operator">=</span> pipeline<span class="token punctuation">;</span>
  <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>通过_pipe方法就将task加到了pipeline里，等待后续执行task进行渲染。<br>prepareView(ecIns, true);<br>prepareView(ecIns, false);<br>分别执行ComponentView和ChartView的init方法，具体怎么找到对应的clazz呢？</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">doPrepare</span><span class="token punctuation">(</span><span class="token parameter">model<span class="token operator">:</span> ComponentModel</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> requireNewView <span class="token operator">=</span> model<span class="token punctuation">.</span>__requireNewView<span class="token punctuation">;</span>
                model<span class="token punctuation">.</span>__requireNewView <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
                <span class="token keyword">const</span> viewId <span class="token operator">=</span> <span class="token string">'_ec_'</span> <span class="token operator">+</span> model<span class="token punctuation">.</span>id <span class="token operator">+</span> <span class="token string">'_'</span> <span class="token operator">+</span> model<span class="token punctuation">.</span>type<span class="token punctuation">;</span>
                <span class="token keyword">let</span> view <span class="token operator">=</span> <span class="token operator">!</span>requireNewView <span class="token operator">&amp;&amp;</span> viewMap<span class="token punctuation">[</span>viewId<span class="token punctuation">]</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>view<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    <span class="token keyword">const</span> classType <span class="token operator">=</span> <span class="token function">parseClassType</span><span class="token punctuation">(</span>model<span class="token punctuation">.</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">const</span> Clazz <span class="token operator">=</span> isComponent
                        <span class="token operator">?</span> <span class="token punctuation">(</span>ComponentView <span class="token keyword">as</span> ComponentViewConstructor<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span>classType<span class="token punctuation">.</span>main<span class="token punctuation">,</span> classType<span class="token punctuation">.</span>sub<span class="token punctuation">)</span>
                        <span class="token operator">:</span> <span class="token punctuation">(</span>
                                     <span class="token punctuation">(</span>ChartView <span class="token keyword">as</span> ChartViewConstructor<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span>classType<span class="token punctuation">.</span>sub<span class="token punctuation">)</span>
                        <span class="token punctuation">)</span><span class="token punctuation">;</span>

                    <span class="token keyword">if</span> <span class="token punctuation">(</span>__DEV__<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                        <span class="token function">assert</span><span class="token punctuation">(</span>Clazz<span class="token punctuation">,</span> classType<span class="token punctuation">.</span>sub <span class="token operator">+</span> <span class="token string">' does not exist.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">&#125;</span>

                    view <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Clazz</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    view<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    viewMap<span class="token punctuation">[</span>viewId<span class="token punctuation">]</span> <span class="token operator">=</span> view<span class="token punctuation">;</span>
                    viewList<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>view <span class="token keyword">as</span> any<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    zr<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>view<span class="token punctuation">.</span>group<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">&#125;</span>

                model<span class="token punctuation">.</span>__viewId <span class="token operator">=</span> view<span class="token punctuation">.</span>__id <span class="token operator">=</span> viewId<span class="token punctuation">;</span>
                view<span class="token punctuation">.</span>__alive <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
                view<span class="token punctuation">.</span>__model <span class="token operator">=</span> model<span class="token punctuation">;</span>
                view<span class="token punctuation">.</span>group<span class="token punctuation">.</span>__ecComponentInfo <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
                    mainType<span class="token operator">:</span> model<span class="token punctuation">.</span>mainType<span class="token punctuation">,</span>
                    index<span class="token operator">:</span> model<span class="token punctuation">.</span>componentIndex
                <span class="token punctuation">&#125;</span><span class="token punctuation">;</span>
                <span class="token operator">!</span>isComponent <span class="token operator">&amp;&amp;</span> scheduler<span class="token punctuation">.</span><span class="token function">prepareView</span><span class="token punctuation">(</span>
                    view <span class="token keyword">as</span> ChartView<span class="token punctuation">,</span> model <span class="token keyword">as</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token punctuation">(</span>ComponentView <span class="token keyword">as</span> ComponentViewConstructor<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getClass</span><span class="token punctuation">(</span>classType<span class="token punctuation">.</span>main<span class="token punctuation">,</span> classType<span class="token punctuation">.</span>sub<span class="token punctuation">)</span>

<span class="token keyword">import</span> <span class="token operator">*</span> <span class="token keyword">as</span> clazzUtil <span class="token keyword">from</span> <span class="token string">'../util/clazz'</span><span class="token punctuation">;</span>
<span class="token keyword">export</span> type ComponentViewConstructor <span class="token operator">=</span> <span class="token keyword">typeof</span> ComponentView
    <span class="token operator">&amp;</span> clazzUtil<span class="token punctuation">.</span>ExtendableConstructor
    <span class="token operator">&amp;</span> clazzUtil<span class="token punctuation">.</span>ClassManager<span class="token punctuation">;</span>

clazzUtil<span class="token punctuation">.</span><span class="token function">enableClassExtend</span><span class="token punctuation">(</span>ComponentView <span class="token keyword">as</span> ComponentViewConstructor<span class="token punctuation">)</span><span class="token punctuation">;</span>
clazzUtil<span class="token punctuation">.</span><span class="token function">enableClassManagement</span><span class="token punctuation">(</span>ComponentView <span class="token keyword">as</span> ComponentViewConstructor<span class="token punctuation">)</span><span class="token punctuation">;</span>

target<span class="token punctuation">.</span><span class="token function-variable function">getClass</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>
        <span class="token parameter">mainType<span class="token operator">:</span> ComponentMainType<span class="token punctuation">,</span>
        subType<span class="token operator">?</span><span class="token operator">:</span> ComponentSubType<span class="token punctuation">,</span>
        throwWhenNotFound<span class="token operator">?</span><span class="token operator">:</span> boolean</span>
    <span class="token punctuation">)</span><span class="token operator">:</span> Constructor <span class="token punctuation">&#123;</span>
        <span class="token keyword">let</span> clz <span class="token operator">=</span> storage<span class="token punctuation">[</span>mainType<span class="token punctuation">]</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>clz <span class="token operator">&amp;&amp;</span> <span class="token punctuation">(</span>clz <span class="token keyword">as</span> SubclassContainer<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token constant">IS_CONTAINER</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            clz <span class="token operator">=</span> subType <span class="token operator">?</span> <span class="token punctuation">(</span>clz <span class="token keyword">as</span> SubclassContainer<span class="token punctuation">)</span><span class="token punctuation">[</span>subType<span class="token punctuation">]</span> <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>throwWhenNotFound <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>clz<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span>
                <span class="token operator">!</span>subType
                    <span class="token operator">?</span> mainType <span class="token operator">+</span> <span class="token string">'.'</span> <span class="token operator">+</span> <span class="token string">'type should be specified.'</span>
                    <span class="token operator">:</span> <span class="token string">'Component '</span> <span class="token operator">+</span> mainType <span class="token operator">+</span> <span class="token string">'.'</span> <span class="token operator">+</span> <span class="token punctuation">(</span>subType <span class="token operator">||</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">' is used but not imported.'</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token keyword">return</span> clz <span class="token keyword">as</span> Constructor<span class="token punctuation">;</span>
 <span class="token punctuation">&#125;</span><span class="token punctuation">;</span>
 
 target<span class="token punctuation">.</span><span class="token function-variable function">registerClass</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span>
        <span class="token parameter">clz<span class="token operator">:</span> Constructor</span>
    <span class="token punctuation">)</span><span class="token operator">:</span> Constructor <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> componentFullType <span class="token operator">=</span> <span class="token punctuation">(</span>clz <span class="token keyword">as</span> any<span class="token punctuation">)</span><span class="token punctuation">.</span>type <span class="token operator">||</span> clz<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>type<span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>componentFullType<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token function">checkClassType</span><span class="token punctuation">(</span>componentFullType<span class="token punctuation">)</span><span class="token punctuation">;</span>
            clz<span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>type <span class="token operator">=</span> componentFullType<span class="token punctuation">;</span>
            <span class="token keyword">const</span> componentTypeInfo <span class="token operator">=</span> <span class="token function">parseClassType</span><span class="token punctuation">(</span>componentFullType<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>componentTypeInfo<span class="token punctuation">.</span>sub<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    storage<span class="token punctuation">[</span>componentTypeInfo<span class="token punctuation">.</span>main<span class="token punctuation">]</span> <span class="token operator">=</span> clz<span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
            <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>componentTypeInfo<span class="token punctuation">.</span>sub <span class="token operator">!==</span> <span class="token constant">IS_CONTAINER</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> container <span class="token operator">=</span> <span class="token function">makeContainer</span><span class="token punctuation">(</span>componentTypeInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
                container<span class="token punctuation">[</span>componentTypeInfo<span class="token punctuation">.</span>sub<span class="token punctuation">]</span> <span class="token operator">=</span> clz<span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">return</span> clz<span class="token punctuation">;</span>
  <span class="token punctuation">&#125;</span><span class="token punctuation">;</span>
  <span class="token comment">//以TitleView为例</span>
  <span class="token keyword">class</span> <span class="token class-name">TitleView</span> <span class="token keyword">extends</span> <span class="token class-name">ComponentView</span> <span class="token punctuation">&#123;</span>

    <span class="token keyword">static</span> type <span class="token operator">=</span> <span class="token string">'title'</span> <span class="token keyword">as</span> <span class="token keyword">const</span><span class="token punctuation">;</span>
    type <span class="token operator">=</span> TitleView<span class="token punctuation">.</span>type<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function">prepareView</span><span class="token punctuation">(</span>view<span class="token operator">:</span> ChartView<span class="token punctuation">,</span> model<span class="token operator">:</span> SeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> renderTask <span class="token operator">=</span> view<span class="token punctuation">.</span>renderTask<span class="token punctuation">;</span>
        <span class="token keyword">const</span> context <span class="token operator">=</span> renderTask<span class="token punctuation">.</span>context<span class="token punctuation">;</span>

        context<span class="token punctuation">.</span>model <span class="token operator">=</span> model<span class="token punctuation">;</span>
        context<span class="token punctuation">.</span>ecModel <span class="token operator">=</span> ecModel<span class="token punctuation">;</span>
        context<span class="token punctuation">.</span>api <span class="token operator">=</span> api<span class="token punctuation">;</span>

        renderTask<span class="token punctuation">.</span>__block <span class="token operator">=</span> <span class="token operator">!</span>view<span class="token punctuation">.</span>incrementalPrepareRender<span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_pipe</span><span class="token punctuation">(</span>model<span class="token punctuation">,</span> renderTask<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>而BarView不同的地方在，将renderTask加入了pipeline。<br>setOption里的<code>prepare(this);</code>执行完了，总结一下就是初始化Model，初始化对应的ComponentView和ChartView并将series对应的task加入pipeline，再来看下<code>updateMethods.update.call(this, null, updateParams);</code></p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript">updateMethods <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
            <span class="token function">update</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token operator">:</span> ECharts<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">,</span> updateParams<span class="token operator">:</span> UpdateLifecycleParams<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> ecModel <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_model<span class="token punctuation">;</span>
                <span class="token keyword">const</span> api <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_api<span class="token punctuation">;</span>
                <span class="token keyword">const</span> zr <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_zr<span class="token punctuation">;</span>
                <span class="token keyword">const</span> coordSysMgr <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_coordSysMgr<span class="token punctuation">;</span>
                <span class="token keyword">const</span> scheduler <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_scheduler<span class="token punctuation">;</span>
                <span class="token comment">// update before setOption</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>ecModel<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    <span class="token keyword">return</span><span class="token punctuation">;</span>
                <span class="token punctuation">&#125;</span>
                ecModel<span class="token punctuation">.</span><span class="token function">setUpdatePayload</span><span class="token punctuation">(</span>payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
                scheduler<span class="token punctuation">.</span><span class="token function">restoreData</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
                scheduler<span class="token punctuation">.</span><span class="token function">performSeriesTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>
                coordSysMgr<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span><span class="token punctuation">;</span>
                scheduler<span class="token punctuation">.</span><span class="token function">performDataProcessorTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token function">updateStreamModes</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>
                coordSysMgr<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token function">clearColorPalette</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>
                scheduler<span class="token punctuation">.</span><span class="token function">performVisualTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
                
                <span class="token function">render</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">,</span> updateParams<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// Set background</span>
                <span class="token keyword">let</span> backgroundColor <span class="token operator">=</span> ecModel<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">'backgroundColor'</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token string">'transparent'</span><span class="token punctuation">;</span>
                <span class="token keyword">const</span> darkMode <span class="token operator">=</span> ecModel<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">'darkMode'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// In IE8</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>env<span class="token punctuation">.</span>canvasSupported<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    <span class="token keyword">const</span> colorArr <span class="token operator">=</span> colorTool<span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>backgroundColor <span class="token keyword">as</span> ColorString<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    backgroundColor <span class="token operator">=</span> colorTool<span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>colorArr<span class="token punctuation">,</span> <span class="token string">'rgb'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span>colorArr<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                        backgroundColor <span class="token operator">=</span> <span class="token string">'transparent'</span><span class="token punctuation">;</span>
                    <span class="token punctuation">&#125;</span>
                <span class="token punctuation">&#125;</span>
                <span class="token keyword">else</span> <span class="token punctuation">&#123;</span>
                    zr<span class="token punctuation">.</span><span class="token function">setBackgroundColor</span><span class="token punctuation">(</span>backgroundColor<span class="token punctuation">)</span><span class="token punctuation">;</span>

                    <span class="token comment">// Force set dark mode.</span>
                    <span class="token keyword">if</span> <span class="token punctuation">(</span>darkMode <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">&amp;&amp;</span> darkMode <span class="token operator">!==</span> <span class="token string">'auto'</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                        zr<span class="token punctuation">.</span><span class="token function">setDarkMode</span><span class="token punctuation">(</span>darkMode<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">&#125;</span>
                <span class="token punctuation">&#125;</span>

                lifecycle<span class="token punctuation">.</span><span class="token function">trigger</span><span class="token punctuation">(</span><span class="token string">'afterupdate'</span><span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>最主要的是<code>render(this, ecModel, api, payload, updateParams);</code>方法，</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function-variable function">render</span> <span class="token operator">=</span> <span class="token punctuation">(</span>
            <span class="token parameter">ecIns<span class="token operator">:</span> ECharts<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">,</span>
            updateParams<span class="token operator">:</span> UpdateLifecycleParams</span>
        <span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span>

            <span class="token function">renderComponents</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">,</span> updateParams<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token function">each</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">.</span>_chartsViews<span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">chart<span class="token operator">:</span> ChartView</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                chart<span class="token punctuation">.</span>__alive <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token function">renderSeries</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">,</span> updateParams<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token comment">// Remove groups of unrendered charts</span>
            <span class="token function">each</span><span class="token punctuation">(</span>ecIns<span class="token punctuation">.</span>_chartsViews<span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">chart<span class="token operator">:</span> ChartView</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>chart<span class="token punctuation">.</span>__alive<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    chart<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">&#125;</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>先来看下<code>renderComponents(ecIns, ecModel, api, payload, updateParams);</code></p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function-variable function">renderComponents</span> <span class="token operator">=</span> <span class="token punctuation">(</span>
            <span class="token parameter">ecIns<span class="token operator">:</span> ECharts<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload<span class="token punctuation">,</span>
            updateParams<span class="token operator">:</span> UpdateLifecycleParams<span class="token punctuation">,</span> dirtyList<span class="token operator">?</span><span class="token operator">:</span> ComponentView<span class="token punctuation">[</span><span class="token punctuation">]</span></span>
        <span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span>
            <span class="token function">each</span><span class="token punctuation">(</span>dirtyList <span class="token operator">||</span> ecIns<span class="token punctuation">.</span>_componentsViews<span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">componentView<span class="token operator">:</span> ComponentView</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> componentModel <span class="token operator">=</span> componentView<span class="token punctuation">.</span>__model<span class="token punctuation">;</span>
                <span class="token function">clearStates</span><span class="token punctuation">(</span>componentModel<span class="token punctuation">,</span> componentView<span class="token punctuation">)</span><span class="token punctuation">;</span>

                componentView<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>componentModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token function">updateZ</span><span class="token punctuation">(</span>componentModel<span class="token punctuation">,</span> componentView<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token function">updateStates</span><span class="token punctuation">(</span>componentModel<span class="token punctuation">,</span> componentView<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>ecIns就是echarts实例，那针对这个示例都有哪些_componentsViews呢，<br><img src="https://img.dengwu.wang/blog/20211114010528.png"><br>拿其中一个TitleView来细看一下</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function">render</span><span class="token punctuation">(</span><span class="token parameter">titleModel<span class="token operator">:</span> TitleModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>group<span class="token punctuation">.</span><span class="token function">removeAll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> group <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>group<span class="token punctuation">;</span>

       
        <span class="token keyword">const</span> textEl <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">graphic<span class="token punctuation">.</span>Text</span><span class="token punctuation">(</span><span class="token punctuation">&#123;</span>
            style<span class="token operator">:</span> <span class="token function">createTextStyle</span><span class="token punctuation">(</span>textStyleModel<span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
                text<span class="token operator">:</span> titleModel<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">'text'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                fill<span class="token operator">:</span> textStyleModel<span class="token punctuation">.</span><span class="token function">getTextColor</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>disableBox<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            z2<span class="token operator">:</span> <span class="token number">10</span>
        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        group<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>textEl<span class="token punctuation">)</span><span class="token punctuation">;</span>
        
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>render方法实在太长了，我删掉了样式，子标题，背景，标题框等相关代码，只留下Text渲染相关的了。<br>可以看到，真正的渲染是调用了zrender的graphic.Text，并添加到了group里。<br>再来看renderSeries</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript">renderSeries <span class="token operator">=</span> <span class="token punctuation">(</span>
            ecIns<span class="token operator">:</span> ECharts<span class="token punctuation">,</span>
            ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span>
            api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span>
            payload<span class="token operator">:</span> Payload <span class="token operator">|</span> <span class="token string">'remain'</span><span class="token punctuation">,</span>
            updateParams<span class="token operator">:</span> UpdateLifecycleParams<span class="token punctuation">,</span>
            dirtyMap<span class="token operator">?</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span><span class="token punctuation">[</span>uid<span class="token operator">:</span> string<span class="token punctuation">]</span><span class="token operator">:</span> any<span class="token punctuation">&#125;</span>
        <span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">&#123;</span>
            <span class="token comment">// Render all charts</span>
            <span class="token keyword">const</span> scheduler <span class="token operator">=</span> ecIns<span class="token punctuation">.</span>_scheduler<span class="token punctuation">;</span>

            updateParams <span class="token operator">=</span> <span class="token function">extend</span><span class="token punctuation">(</span>updateParams <span class="token operator">||</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> <span class="token punctuation">&#123;</span>
                updatedSeries<span class="token operator">:</span> ecModel<span class="token punctuation">.</span><span class="token function">getSeries</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">let</span> unfinished<span class="token operator">:</span> boolean <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
            ecModel<span class="token punctuation">.</span><span class="token function">eachSeries</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">seriesModel</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> chartView <span class="token operator">=</span> ecIns<span class="token punctuation">.</span>_chartsMap<span class="token punctuation">[</span>seriesModel<span class="token punctuation">.</span>__viewId<span class="token punctuation">]</span><span class="token punctuation">;</span>
                chartView<span class="token punctuation">.</span>__alive <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>

                <span class="token keyword">const</span> renderTask <span class="token operator">=</span> chartView<span class="token punctuation">.</span>renderTask<span class="token punctuation">;</span>
                 <span class="token keyword">if</span> <span class="token punctuation">(</span>renderTask<span class="token punctuation">.</span><span class="token function">perform</span><span class="token punctuation">(</span>scheduler<span class="token punctuation">.</span><span class="token function">getPerformArgs</span><span class="token punctuation">(</span>renderTask<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                    unfinished <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
                <span class="token punctuation">&#125;</span>

            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>最重要的就是调用了renderTask.perform<br>Task(src/core/task.ts)的perform方法。方法比较长，我就不贴代码了，主干是调用了<code>                    this._doProgress(progress, start, end, modBy, modDataCount);</code></p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">const</span> progressMethodMap<span class="token operator">:</span> <span class="token punctuation">&#123;</span><span class="token punctuation">[</span>method<span class="token operator">:</span> string<span class="token punctuation">]</span><span class="token operator">:</span> TaskResetCallbackReturn<span class="token operator">&lt;</span>SeriesTaskContext<span class="token operator">></span><span class="token punctuation">&#125;</span> <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
    incrementalPrepareRender<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
        <span class="token function-variable function">progress</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">params<span class="token operator">:</span> StageHandlerProgressParams<span class="token punctuation">,</span> context<span class="token operator">:</span> SeriesTaskContext</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
            context<span class="token punctuation">.</span>view<span class="token punctuation">.</span><span class="token function">incrementalRender</span><span class="token punctuation">(</span>
                params<span class="token punctuation">,</span> context<span class="token punctuation">.</span>model<span class="token punctuation">,</span> context<span class="token punctuation">.</span>ecModel<span class="token punctuation">,</span> context<span class="token punctuation">.</span>api<span class="token punctuation">,</span> context<span class="token punctuation">.</span>payload
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
    render<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
        <span class="token comment">// Put view.render in `progress` to support appendData. But in this case</span>
        <span class="token comment">// view.render should not be called in reset, otherwise it will be called</span>
        <span class="token comment">// twise. Use `forceFirstProgress` to make sure that view.render is called</span>
        <span class="token comment">// in any cases.</span>
        forceFirstProgress<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        <span class="token function-variable function">progress</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">params<span class="token operator">:</span> StageHandlerProgressParams<span class="token punctuation">,</span> context<span class="token operator">:</span> SeriesTaskContext</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
            context<span class="token punctuation">.</span>view<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>
                context<span class="token punctuation">.</span>model<span class="token punctuation">,</span> context<span class="token punctuation">.</span>ecModel<span class="token punctuation">,</span> context<span class="token punctuation">.</span>api<span class="token punctuation">,</span> context<span class="token punctuation">.</span>payload
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>紧接着调用了progress方法，而progress方法里调用了view的render，以此示例的BarView举例</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function">render</span><span class="token punctuation">(</span><span class="token parameter">seriesModel<span class="token operator">:</span> BarSeriesModel<span class="token punctuation">,</span> ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span> api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span> payload<span class="token operator">:</span> Payload</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>_model <span class="token operator">=</span> seriesModel<span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_removeOnRenderedListener</span><span class="token punctuation">(</span>api<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_updateDrawMode</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">const</span> coordinateSystemType <span class="token operator">=</span> seriesModel<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token string">'coordinateSystem'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>coordinateSystemType <span class="token operator">===</span> <span class="token string">'cartesian2d'</span>
            <span class="token operator">||</span> coordinateSystemType <span class="token operator">===</span> <span class="token string">'polar'</span>
        <span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>_isLargeDraw
                <span class="token operator">?</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_renderLarge</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">)</span>
                <span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_renderNormal</span><span class="token punctuation">(</span>seriesModel<span class="token punctuation">,</span> ecModel<span class="token punctuation">,</span> api<span class="token punctuation">,</span> payload<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>__DEV__<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token function">warn</span><span class="token punctuation">(</span><span class="token string">'Only cartesian2d and polar supported for bar.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
    <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>根据是否是_isLargeDraw而分别调用不同的render，本示走的是_renderNormal方法。</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">private</span> <span class="token function">_renderNormal</span><span class="token punctuation">(</span>
        seriesModel<span class="token operator">:</span> BarSeriesModel<span class="token punctuation">,</span>
        ecModel<span class="token operator">:</span> GlobalModel<span class="token punctuation">,</span>
        api<span class="token operator">:</span> ExtensionAPI<span class="token punctuation">,</span>
        payload<span class="token operator">:</span> Payload
    <span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> group <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>group<span class="token punctuation">;</span>
        <span class="token keyword">const</span> data <span class="token operator">=</span> seriesModel<span class="token punctuation">.</span><span class="token function">getData</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">const</span> oldData <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_data<span class="token punctuation">;</span>
        data<span class="token punctuation">.</span><span class="token function">diff</span><span class="token punctuation">(</span>oldData<span class="token punctuation">)</span>
            <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">dataIndex</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> itemModel <span class="token operator">=</span> data<span class="token punctuation">.</span>getItemModel<span class="token operator">&lt;</span>BarDataItemOption<span class="token operator">></span><span class="token punctuation">(</span>dataIndex<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">const</span> layout <span class="token operator">=</span> getLayout<span class="token punctuation">[</span>coord<span class="token punctuation">.</span>type<span class="token punctuation">]</span><span class="token punctuation">(</span>data<span class="token punctuation">,</span> dataIndex<span class="token punctuation">,</span> itemModel<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">const</span> el <span class="token operator">=</span> elementCreator<span class="token punctuation">[</span>coord<span class="token punctuation">.</span>type<span class="token punctuation">]</span><span class="token punctuation">(</span>
                    seriesModel<span class="token punctuation">,</span>
                    data<span class="token punctuation">,</span>
                    dataIndex<span class="token punctuation">,</span>
                    layout<span class="token punctuation">,</span>
                    isHorizontalOrRadial<span class="token punctuation">,</span>
                    animationModel<span class="token punctuation">,</span>
                    baseAxis<span class="token punctuation">.</span>model<span class="token punctuation">,</span>
                    <span class="token boolean">false</span><span class="token punctuation">,</span>
                    roundCap
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
                group<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>el<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
            <span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>_data <span class="token operator">=</span> data<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span>
    
    <span class="token keyword">const</span> elementCreator<span class="token operator">:</span> <span class="token punctuation">&#123;</span>
    <span class="token punctuation">[</span>key <span class="token keyword">in</span> <span class="token string">'polar'</span> <span class="token operator">|</span> <span class="token string">'cartesian2d'</span><span class="token punctuation">]</span><span class="token operator">:</span> ElementCreator
<span class="token punctuation">&#125;</span> <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
    <span class="token function">cartesian2d</span><span class="token punctuation">(</span>
        <span class="token parameter">seriesModel<span class="token punctuation">,</span> data<span class="token punctuation">,</span> newIndex<span class="token punctuation">,</span> layout<span class="token operator">:</span> RectLayout<span class="token punctuation">,</span> isHorizontal<span class="token punctuation">,</span>
        animationModel<span class="token punctuation">,</span> axisModel<span class="token punctuation">,</span> isUpdate<span class="token punctuation">,</span> roundCap</span>
    <span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">const</span> rect <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Rect</span><span class="token punctuation">(</span><span class="token punctuation">&#123;</span>
            shape<span class="token operator">:</span> <span class="token function">extend</span><span class="token punctuation">(</span><span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">,</span> layout<span class="token punctuation">)</span><span class="token punctuation">,</span>
            z2<span class="token operator">:</span> <span class="token number">1</span>
        <span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">(</span>rect <span class="token keyword">as</span> any<span class="token punctuation">)</span><span class="token punctuation">.</span>__dataIndex <span class="token operator">=</span> newIndex<span class="token punctuation">;</span>

        rect<span class="token punctuation">.</span>name <span class="token operator">=</span> <span class="token string">'item'</span><span class="token punctuation">;</span>

        <span class="token keyword">if</span> <span class="token punctuation">(</span>animationModel<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">const</span> rectShape <span class="token operator">=</span> rect<span class="token punctuation">.</span>shape<span class="token punctuation">;</span>
            <span class="token keyword">const</span> animateProperty <span class="token operator">=</span> isHorizontal <span class="token operator">?</span> <span class="token string">'height'</span> <span class="token operator">:</span> <span class="token string">'width'</span> <span class="token keyword">as</span> <span class="token string">'width'</span> <span class="token operator">|</span> <span class="token string">'height'</span><span class="token punctuation">;</span>
            rectShape<span class="token punctuation">[</span>animateProperty<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token keyword">return</span> rect<span class="token punctuation">;</span>
    <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>方法太长，我删掉了非主干代码，可以看到最终根据Model的data的diff来进行add,update,remove,最终还是调用了zrender的Rect来画出bar的样子。<br>最后贴一下渲染BarView的调用栈<br><img src="https://img.dengwu.wang/blog/20211114021358.png"><br>渲染ComponentView比较直接，而渲染ChartView类型的就绕来绕去，主要原因是ChartView可能数据比较多，需要逐步分批渲染，以减少卡顿，保持每秒60帧的渲染，因为1000ms，每一帧不能超过16ms，才能保持流畅的渲染。<br>在setOption方法的最后调用了<code>this._zr.flush();</code>则直接将绘制渲染出来了，当然对于ChartView的绘制，可能还需要等到下一次渲染的时候才会显示出来。</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">private</span> <span class="token function">_onframe</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span> <span class="token punctuation">&#123;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>_disposed<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">return</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>

        <span class="token function">applyChangedStates</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token keyword">const</span> scheduler <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_scheduler<span class="token punctuation">;</span>

        <span class="token comment">// Lazy update</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token keyword">const</span> silent <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span> <span class="token keyword">as</span> any<span class="token punctuation">)</span><span class="token punctuation">.</span>silent<span class="token punctuation">;</span>

            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">IN_MAIN_PROCESS_KEY</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>

            <span class="token function">prepare</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            updateMethods<span class="token punctuation">.</span><span class="token function">update</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span><span class="token punctuation">.</span>updateParams<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token comment">// At present, in each frame, zrender performs:</span>
            <span class="token comment">//   (1) animation step forward.</span>
            <span class="token comment">//   (2) trigger('frame') (where this `_onframe` is called)</span>
            <span class="token comment">//   (3) zrender flush (render).</span>
            <span class="token comment">// If we do nothing here, since we use `setToFinal: true`, the step (3) above</span>
            <span class="token comment">// will render the final state of the elements before the real animation started.</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>_zr<span class="token punctuation">.</span><span class="token function">flush</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">IN_MAIN_PROCESS_KEY</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>

            <span class="token keyword">this</span><span class="token punctuation">[</span><span class="token constant">PENDING_UPDATE</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>

            <span class="token function">flushPendingActions</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> silent<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token function">triggerUpdatedEvent</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> silent<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">&#125;</span>
        <span class="token comment">// Avoid do both lazy update and progress in one frame.</span>
        <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>scheduler<span class="token punctuation">.</span>unfinished<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
            <span class="token comment">// Stream progress.</span>
            <span class="token keyword">let</span> remainTime <span class="token operator">=</span> <span class="token constant">TEST_FRAME_REMAIN_TIME</span><span class="token punctuation">;</span>
            <span class="token keyword">const</span> ecModel <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_model<span class="token punctuation">;</span>
            <span class="token keyword">const</span> api <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_api<span class="token punctuation">;</span>
            scheduler<span class="token punctuation">.</span>unfinished <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
            <span class="token keyword">do</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">const</span> startTime <span class="token operator">=</span> <span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                scheduler<span class="token punctuation">.</span><span class="token function">performSeriesTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// Currently dataProcessorFuncs do not check threshold.</span>
                scheduler<span class="token punctuation">.</span><span class="token function">performDataProcessorTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token function">updateStreamModes</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// Do not update coordinate system here. Because that coord system update in</span>
                <span class="token comment">// each frame is not a good user experience. So we follow the rule that</span>
                <span class="token comment">// the extent of the coordinate system is determin in the first frame (the</span>
                <span class="token comment">// frame is executed immedietely after task reset.</span>
                <span class="token comment">// this._coordSysMgr.update(ecModel, api);</span>

                <span class="token comment">// console.log('--- ec frame visual ---', remainTime);</span>
                scheduler<span class="token punctuation">.</span><span class="token function">performVisualTasks</span><span class="token punctuation">(</span>ecModel<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token function">renderSeries</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>_model<span class="token punctuation">,</span> api<span class="token punctuation">,</span> <span class="token string">'remain'</span><span class="token punctuation">,</span> <span class="token punctuation">&#123;</span><span class="token punctuation">&#125;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                remainTime <span class="token operator">-=</span> <span class="token punctuation">(</span><span class="token operator">+</span><span class="token keyword">new</span> <span class="token class-name">Date</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">-</span> startTime<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
            <span class="token keyword">while</span> <span class="token punctuation">(</span>remainTime <span class="token operator">></span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> scheduler<span class="token punctuation">.</span>unfinished<span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token comment">// Call flush explicitly for trigger finished event.</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>scheduler<span class="token punctuation">.</span>unfinished<span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
                <span class="token keyword">this</span><span class="token punctuation">.</span>_zr<span class="token punctuation">.</span><span class="token function">flush</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">&#125;</span>
            <span class="token comment">// Else, zr flushing be ensue within the same frame,</span>
            <span class="token comment">// because zr flushing is after onframe event.</span>
        <span class="token punctuation">&#125;</span>
   <span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
<p>对于echarts的渲染分析就到这了，下次有机会我们自己动手写一个ChartView。</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://dengwu.wang" rel="external nofollow noreferrer">王登武</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                    </span>
                <span class="reprint-info">
                    <a href="https://dengwu.wang/2021/11/10/echarts5-tu-biao-xuan-ran-guo-cheng-fen-xi/">https://dengwu.wang/2021/11/10/echarts5-tu-biao-xuan-ran-guo-cheng-fen-xi/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by-nc-nd/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY-NC-ND 4.0</a>
                    许可协议。转载请注明来源
                    <a href="https://dengwu.wang" target="_blank">王登武</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/%E5%9B%BE%E8%A1%A8-echarts/">
                                    <span class="chip bg-color">图表 - echarts</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="qq,qzone,wechat,weibo" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 wechat-tab waves-effect waves-light">
                            <a href="#wechat">微 信</a>
                        </li>
                        <li class="tab col s6 alipay-tab waves-effect waves-light">
                            <a href="#alipay">支付宝</a>
                        </li>
                    </ul>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信打赏二维码">
                    </div>
                    <div id="alipay">
                        <img src="/medias/reward/alipay1.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    <script src="https://utteranc.es/client.js"
        repo="wangdengwu/wangdengwu.github.io"
        issue-term="pathname"
        theme="github-light"
        crossorigin="anonymous"
        async>
    </script>

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2021/11/24/han-shu-shi-bian-cheng-jian-jie/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/12.jpg" class="responsive-img" alt="函数式编程简介">
                        
                        <span class="card-title">函数式编程简介</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2021-11-24
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/" class="post-category">
                                    函数式编程
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E5%87%BD%E6%95%B0%E5%BC%8F%E7%BC%96%E7%A8%8B/">
                        <span class="chip bg-color">函数式编程</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2021/11/02/vue3-xin-te-xing/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/13.jpg" class="responsive-img" alt="Vue3 新特性">
                        
                        <span class="card-title">Vue3 新特性</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2021-11-02
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/vue/" class="post-category">
                                    vue
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/vue3/">
                        <span class="chip bg-color">vue3</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: 武码公社<br />'
            + '文章作者: 王登武<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2021-2022</span>
            
            <!-- <a href="/about" target="_blank">王登武</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a> -->
            <!-- <br> -->
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">31.6k</span>
            
            
            
            
            
            <!-- <br> -->

            <!-- 运行天数提醒. -->
            
            <br>
            
                <span id="icp"><img src="/medias/icp.png"
                                    style="vertical-align: text-bottom;"/>
                <a href="https://beian.miit.gov.cn/" target="_blank">陕ICP备2021012627号-2</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link ">
    <a href="https://github.com/wangdengwu" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:me@dengwu.wang" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=251472795" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 251472795" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>





    <a href="https://www.zhihu.com/people/wangdengwu" class="tooltipped" target="_blank" data-tooltip="关注我的知乎: https://www.zhihu.com/people/wangdengwu" data-position="top" data-delay="50">
        <i class="fab fa-zhihu1">知</i>
    </a>



</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
